<!DOCTYPE html>
<html>

<head>
	<meta charset="utf-8">
	<title>NicePage demo</title>
	<meta name="renderer" content="webkit">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<link href="../jqueryNicepage/css/layui.css" type="text/css" rel="stylesheet">
	<link rel="stylesheet" href="../styles/common.css"/>
	<link rel="stylesheet" href="../styles/base.css"/>
	<style>
		.layui-table thead th i{
			font-size: 12px;
		}
	</style>
</head>

<body>
	<center style="">
		<div style="width: 80%;">

			<div id="table"></div>
			<div id="pageBar">
				<span>您一共选择了<i>0</i>条数据</span>
			</div>
		</div>

	</center>
</body>
<!--<script type="text/javascript" src="../js/jquery-1.11.3.min.js"></script>-->
<script language="Javascript" src="../jqueryNicepage/js/layui.js"></script>
<script language="Javascript" src="../jqueryNicepage/js/nicePage.js"></script>
<script LANGUAGE="javascript">
	$("#pageBar").css({
		display:"none"
	});
	//window.location.reload();
	var arrFlage=[];
	window.arrFlage=arrFlage;
	//标准json格式 目前只支持[{a:b,c:d},{a:b,c:d}]此种格式
	var json=window.objV;
	var dataListObj=[];
		var nameList = window.headers //table的列名
		var widthList = window.widths//table每列的宽度
		$(function () {
			nicePage.setCfg({
				table: 'table',
				bar: 'pageBar',
				limit: 20,
				color: '#1E9FFF',
				layout: ['count', 'prev', 'page', 'next', 'limit', 'skip']
			});
			$("#loading").css({
				display:"none"
			});
		});//初始化完成

	$('body').unbind("click").on('click','tr td input',function () {
		var father=$(this).parents("tr");
		var tdText=$(father).find("td:nth-child(3) input").val();
		var tdEff=$(father).find("td:nth-child(4) input").val();
		var versionText=$(father).find("td:nth-last-child(1)").text();
		var texts=tdText+"("+tdEff+"),"+versionText;
		var index=getIndexof(arrFlage,texts);
		if(index<0){
			arrFlage.push(texts);
		}else{
			arrFlage.splice(index, 1);
			$("#checkAllData").removeProp("checked","checked")
		}
		var flage=0;
		for(var i=0;i<$(".checkboxS").length;i++){
			if($(".checkboxS").eq(i).prop('checked')){
				//flage=true;
			}else{

				flage+=1;
			}
		}
		if(flage==0){
			$("#checkAllData").prop("checked","checked")
		}
		$(".layui-laypage-count i").text(arrFlage.length)
	});
	function getIndexof(textsArr,value){
		var index;
		if(!textsArr.indexOf){
			textsArr.indexOf = function(elt /*, from*/){
				var len = this.length >>> 0;
				var from = Number(arguments[1]) || 0;
				from = (from < 0)
						? Math.ceil(from)
						: Math.floor(from);
				if (from < 0)
					from += len;
				for (; from < len; from++)
				{
					if (from in this &&
							this[from] === elt)
						return from;
				}
				return -1;
			};
			index=textsArr.indexOf(value);
		}else{
			index= textsArr.indexOf(value);
		}
		return index;
	}
	$("body").on("click","#checkAllData",function(){

		if($('#checkAllData').prop('checked')){//第一次点击
			$(".dataListsCol input").prop("checked","checked");
			for(var i=0;i<$(".dataListsCol").length;i++){
				var tdText=$(".dataListsCol").eq(i).find("td:nth-child(3) input").val();
				var tdEff=$(".dataListsCol").eq(i).find("td:nth-child(4) input").val();
				var versionText=$(".dataListsCol").eq(i).find("td:nth-last-child(1)").text();
				var texts=tdText+"("+tdEff+"),"+versionText;
				var index=getIndexof(arrFlage,texts);
				if(index==(-1)){
					arrFlage.push(texts);
				}
			}
		}else{//第二次点击
			$(".dataListsCol input").removeProp("checked");
			for(var i=0;i<$(".dataListsCol").length;i++){
				var tdText=$(".dataListsCol").eq(i).find("td:nth-child(3) input").val();
				var tdEff=$(".dataListsCol").eq(i).find("td:nth-child(4) input").val();
				var versionText=$(".dataListsCol").eq(i).find("td:nth-last-child(1)").text();
				var texts=tdText+"("+tdEff+"),"+versionText;
				var index=getIndexof(arrFlage,texts);
				if(index>(-1)){
					arrFlage.splice(index, 1);
				}
			}
		}
		$(".layui-laypage-count i").text(arrFlage.length)
	});
	$(document).click(function(){
		var flage=0;
		for(var i=0;i<$(".dataListsCol").length;i++){
			var effView=$(".dataListsCol").eq(i).find('.td0 input').val()+$(".dataListsCol").eq(i).find('.td1 input').val()+$(".dataListsCol").eq(i).find('.td3').text();
			if(getIndexof(arrFlage,effView)>(-1)){
				$(".checkboxS").eq(i).prop("checked","checked");
			}else{

				//flage+=1;
			}
		}
		for(var m=0;m<$(".checkboxS").length;m++){
			if($(".checkboxS").eq(m).prop('checked')){
				flage+=1;
			}else{


			}
		}
		if(flage==$(".checkboxS").length){
			$("#checkAllData").prop("checked","checked")
		}
		$(".layui-laypage-count i").text(arrFlage.length)
	})
	$("body").on("click","thead tr th:first-child +th+th",function(){
		$("#loading").css({
			display:"block"
		});
		$("#pageBar").css({
			display:"none"
		});
		var className=$(this).find("i").attr("class").split(" ")[1];
		if(className=="up"){
			var icon=["全选","序号","受影响对象料号"+"<i title='从小到大' class='iconfont down'>&#xe604;</i>","视图"+"<i title='从大到小' class='iconfont up'>&#xe64d;</i>","受影响对象状态"];
			json=window.objV.sort(compareUp(window.objV,"number"));
		}else{
			var icon=["全选","序号","受影响对象料号"+"<i title='从大到小' class='iconfont up'>&#xe64d;</i>","视图"+"<i title='从大到小' class='iconfont up'>&#xe64d;</i>","受影响对象状态"];
			json=window.objV.sort(compareDown(window.objV,"number"));
		}


		window.headers=icon;
		$(".formContent").remove();
		$(".searchContainer").append('<div class="formContent"></div>')
		$(".formContent").empty().load('./index.html',"",function(){
			$("#pageBar").css({
				"width":$(".searchContainer").width(),
				"text-align":"center"
			});
			setTimeout(function(){
				var heightform=$(".searchContainer").height()-$(".seachHeader").height()-20;
				/* console.log($(".layui-table").height());
                 console.log($(".formContent").height());*/
				if($(".formContent")[0].offsetHeight>(heightform*0.90)){
					$("#pageBar").css("top",heightform*0.90+$(".seachHeader").height()+20)
				}else{
					$("#pageBar").css("top",$(".formContent")[0].offsetHeight+$(".seachHeader").height()+80);
				}
				$(".formContent").css({
					"max-height":heightform*0.90,
					"overflow-y":"scroll"
				});
				$("#pageBar").css({
					display:"block"
				});
				clearTimeout();
			},100)
		});
	})
	$("body").on("click","thead tr th:first-child +th+th+th",function(){
		$("#loading").css({
			display:"block"
		});

		var className=$(this).find("i").attr("class").split(" ")[1];
		var classNameTh=$(this).prev().find("i").attr("class");
		if(className=="up"){
			var icon=["全选","序号","受影响对象料号"+"<i title='从大到小' class='iconfont down'>&#xe64d;</i>","视图"+"<i title='从小到大' class='iconfont down'>&#xe604;</i>","受影响对象状态"];
			json=window.objV.sort(compareUp(window.objV,"view"));
		}else{
			var icon=["全选","序号","受影响对象料号"+"<i title='从大到小' class='iconfont up'>&#xe64d;</i>","视图"+"<i title='从大到小' class='iconfont up'>&#xe64d;</i>","受影响对象状态"];
			json=window.objV.sort(compareDown(window.objV,"view"));
		}
		window.headers=icon;
		$(".formContent").remove();
		$(".searchContainer").append('<div class="formContent"></div>')

		$(".formContent").empty().load('./index.html',"",function(){
			$("#pageBar").css({
				"width":$(".searchContainer").width(),
				"text-align":"center"
			});
			setTimeout(function(){
				var heightform=$(".searchContainer").height()-$(".seachHeader").height()-20;
				/* console.log($(".layui-table").height());
                 console.log($(".formContent").height());*/
				if($(".formContent")[0].offsetHeight>(heightform*0.90)){
					$("#pageBar").css("top",heightform*0.90+$(".seachHeader").height()+20)
				}else{
					$("#pageBar").css("top",$(".formContent")[0].offsetHeight+$(".seachHeader").height()+80);
				}
				$("#pageBar").css({
					display:"block"
				});
				$(".formContent").css({
					"max-height":heightform*0.90,
					"overflow-y":"scroll"
				});
				clearTimeout();
			},100)
		});
	})
	//把选中的数据提交到ecotabs页面去渲染；
	$(".submitData").unbind("click").click(function(){
		var arrl=arrFlage;
		if(arrl.length>0){
			var effList=[];
			for(var li=0;li<arrl.length;li++){
				var list= arrl[li].split(",")[0];
				effList.push(list);
			}
			localStorage.setItem("dataArr",effList);
			window.location.href="about:blank";
			window.opener=null;
			window.open('','_self');
			window.close();
		}


	})
</script>

</html>